package com.hskn.hss.module.statistics.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.module.tlcar.service.ITlCarService;
import com.hskn.hss.module.tlemployee.service.ITlEmployeeService;
import com.hskn.hss.utils.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 机构资源分布
 *
 * @author hskn
 * @since 2021-05-25
 */
@Slf4j
@RestController
@RequestMapping("/hss/institutionalresources")
public class InstitutionalResourcesController {

    @Autowired
    private ITlEmployeeService tlEmployeeService;

    @Autowired
    private ITlCarService tlCarService;

    /**
     * 人员分布
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "getPersonnelDistribution", method = RequestMethod.POST)
    public AjaxResult<Object> getPersonnelDistribution(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = new JSONObject();
            int currentNumber = tlEmployeeService.getCurrentNumber(params);
            json.put(" currentNumber", currentNumber);
            int departureNumber = tlEmployeeService.getDepartureNumber(params);
            json.put("departureNumber", departureNumber);
            JSONObject jobCategories = tlEmployeeService.getJobCategories(params);
            json.put("jobCategories", jobCategories);
            JSONObject workerType = tlEmployeeService.getWorkerType(params);
            json.put("workerType", workerType);
            JSONObject age = tlEmployeeService.getAge(params);
            json.put("age", age);
            JSONObject gender = tlEmployeeService.getGender(params);
            json.put("gender", gender);
            JSONObject education = tlEmployeeService.getEducation(params);
            json.put("education", education);
            JSONObject national = tlEmployeeService.getNational(params);
            json.put("national", national);
            JSONObject political = tlEmployeeService.getPolitical(params);
            json.put("political", political);
            return AjaxResult.success(json);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 车辆分布
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "getCarDistribution", method = RequestMethod.POST)
    public AjaxResult<Object> getCarDistribution(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = new JSONObject();
            int currentCar = tlCarService.getCurrentCar(params);
            json.put("currentCar", currentCar);
            int endOfLifeCar = tlCarService.getEndOfLifeCar(params);
            json.put("endOfLifeCar", endOfLifeCar);
            JSONObject jobCategories = tlCarService.getJobCategories(params);
            json.put("jobCategories", jobCategories);
            JSONObject carType = tlCarService.getCarType(params);
            json.put("carType", carType);
            JSONObject driveWay = tlCarService.getDriveWay(params);
            json.put("driveWay", driveWay);
            JSONObject ownershipOfCar = tlCarService.getOwnershipOfCar(params);
            json.put("ownershipOfCar", ownershipOfCar);
            JSONObject carManufacturers = tlCarService.getCarManufacturers(params);
            json.put("carManufacturers", carManufacturers);
            JSONObject oldDistribution = tlCarService.getOldDistribution(params);
            json.put("oldDistribution", oldDistribution);
            return AjaxResult.success(json);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }
}
